package com.hxkj.controller;

import com.hxkj.domain.po.Department;
import com.hxkj.service.DepartmentService;
import com.platform.common.dispatcher.util.ResultStructUtils;
import com.platform.common.domain.result.ParameterDataStruct;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultPageStruct;
import com.platform.common.domain.to.PageTo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.Callable;

/**
 * 部门控制器
 * <p>
 * Create by chenwei on 2018/5/22 9:38
 */
@RestController
@Slf4j
@RequestMapping("/department")
public class DepartmentController {


    @Autowired
    private DepartmentService departmentService;

    /**
     * 获取部门
     *
     * @param parameterDataStruct 功能列表
     * @return 翻页数据
     * @throws Exception
     */
    @RequestMapping(value = "/all", method = RequestMethod.GET, consumes = "application/json;charset=UTF-8")
    public Callable<ResultPageStruct<Department>> getDepartments(@RequestBody ParameterDataStruct<Department> parameterDataStruct) throws Exception {
        Department department = parameterDataStruct.getData();
        PageTo pageTo = parameterDataStruct.getPageTo();
        return () -> ResultStructUtils.buildResultPageStruct(departmentService.getDepartmentList(department == null ? new Department() : department, pageTo));
    }


    /**
     * 获取部门
     *
     * @param departMentId 部门id
     * @throws Exception
     */
    @RequestMapping(value = "/{id}", method = RequestMethod.GET, consumes = "application/json;charset=UTF-8")
    public Callable<ResultDataStruct<Department>> getDepartment(@PathVariable("id") Long departMentId) throws Exception {
        return () -> departmentService.get(departMentId);
    }
}
